package com.report.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.report.dto.request.TagReq;
import com.report.dto.response.TagRes;
import com.report.entity.Tag;
import com.report.service.ITagService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author summer
 * @since 2024/06/25 14:55:17
 * 研报标签
 */
@RestController
@RequestMapping("/tag")
@AllArgsConstructor
public class TagController implements BaseCommonInterface<TagReq, TagRes> {


    private final ITagService tagService;

    @Override
    public Result<String> save(@Valid TagReq tagReq) {
        tagService.saveTag(Convert.convert(Tag.class, tagReq));
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        tagService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<TagRes>> lists(TagReq tagReq) {
        return Result.successResult(tagService.lists(tagReq));
    }

    @Override
    public Result<TagRes> findById(Integer id) {
        return Result.successResult(Convert.convert(TagRes.class,tagService.getById(id)));
    }

    @Override
    public Result<String> batchDel(List<TagRes> list) {
        return Result.successResult();
    }



    @GetMapping(value = "/tagLists/{markId}")
    public Result<List<TagRes>> tagLists(@PathVariable Integer markId){

        return Result.successResult(tagService.tagLists(markId));
    }
}
